import { createRouter, createWebHistory } from 'vue-router'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
      component: () => import('@/Layout/index.vue'),
      children: [
        {
          path: '/home',
          component: () => import('@/views/Home/index.vue'),
          meta: { title: '首页' }
        },
      ]
    },
  ],
})
//前置路由守卫
router.beforeEach((to) => {
  //开启进度条
  NProgress.start()
  //获取token
  //const store = useUserStore()
  //白名单
  const whiteList = ['/login']
  //判断是否登录且不在白名单中
  //if (!store.user.token && !whiteList.includes(to.path)) {
  // return '/login'
  //}
})
//后置路由守卫
router.afterEach((to) => {
  //关闭进度条
  NProgress.done()
  //修改页面标题
  document.title = `${to.meta.title || ''}-可视化`
})
export default router
